package com.demo.androidgame.samgukji_hit;

import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import com.demo.androidgame.fx.Game;
import com.demo.androidgame.fx.Input.TouchEvent;
import com.demo.androidgame.fx.gl.Camera2D;
import com.demo.androidgame.fx.gl.SpriteBatcher;
import com.demo.androidgame.fx.impl.GLScreen;
import com.demo.androidgame.fx.math.OverlapTester;
import com.demo.androidgame.fx.math.Rectangle;
import com.demo.androidgame.fx.math.Vector2;

public class SelectScreen extends GLScreen {

	Camera2D guiCam;
	SpriteBatcher batcher;
	Rectangle Mujang1;
	Rectangle Mujang2;
	Rectangle Mujang3;
	Rectangle Mujang4;
	Rectangle Mujang5;
	Rectangle Mujang6;

	Vector2 touchPoint;

	public static int herono;
	
	public SelectScreen(Game game) {
		super(game);
		guiCam = new Camera2D(glGraphics, 800, 480);
		batcher = new SpriteBatcher(glGraphics, 100);
		Mujang1 = new Rectangle(95 - 60, 310 - 75, 120, 150);
		Mujang2 = new Rectangle(195 - 60, 15, 120, 150);
		Mujang3 = new Rectangle(450 - 60, 310 - 75, 120, 150);
		Mujang4 = new Rectangle(350 - 60, 15, 120, 150);
		Mujang5 = new Rectangle(605 - 60, 310 - 75, 120, 150);
		Mujang6 = new Rectangle(705 - 60, 15, 120, 150);

		touchPoint = new Vector2();
		
	}

	@Override
	public void update(float deltaTime) {
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();

		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {
				touchPoint.set(event.x, event.y);
				guiCam.touchToWorld(touchPoint);

				if (OverlapTester.pointInRectangle(Mujang1, touchPoint)) {
					herono = 311;
					game.setScreen(new NationScreen(game));
				}
				if (OverlapTester.pointInRectangle(Mujang2, touchPoint)) {
					herono = 312;
					game.setScreen(new NationScreen(game));
				}
				if (OverlapTester.pointInRectangle(Mujang3, touchPoint)) {
					herono = 313;
					game.setScreen(new NationScreen(game));
				}
				if (OverlapTester.pointInRectangle(Mujang4, touchPoint)) {
					herono = 314;
					game.setScreen(new NationScreen(game));
				}
				if (OverlapTester.pointInRectangle(Mujang5, touchPoint)) {
					herono = 315;
					game.setScreen(new NationScreen(game));
				}
				if (OverlapTester.pointInRectangle(Mujang6, touchPoint)) {
					herono = 316;
					game.setScreen(new NationScreen(game));
				}
			}
		}
	}

	@Override
	public void present(float deltaTime) {
		GL10 gl = glGraphics.getGL();
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		guiCam.setViewportAndMatrices();

		gl.glEnable(GL10.GL_TEXTURE_2D);

		batcher.beginBatch(Assets.select_bar);
		batcher.drawSprite(145, 200, 240, 380, Assets.select_red);
		batcher.drawSprite(145 + 240 + 15, 200, 240, 380, Assets.select_green);
		batcher.drawSprite(145 + 240 + 240 + 30, 200, 240, 380, Assets.select_blue);
		batcher.endBatch();

		batcher.beginBatch(Assets.mujang);
		batcher.drawSprite(95, 310, 120, 150, Assets.mujang1);
		batcher.drawSprite(195, 90, 120, 150, Assets.mujang2);
		batcher.drawSprite(450, 310, 120, 150, Assets.mujang3);
		batcher.drawSprite(350, 90, 120, 150, Assets.mujang4);
		batcher.drawSprite(605, 310, 120, 150, Assets.mujang5);
		batcher.drawSprite(705, 90, 120, 150, Assets.mujang6);
		batcher.endBatch();

		gl.glEnable(GL10.GL_BLEND);
		gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

		batcher.beginBatch(Assets.select_text);
		batcher.drawSprite(400, 480 - 45, 400, 80, Assets.select_textRegion);
		batcher.endBatch();
		
		gl.glDisable(GL10.GL_BLEND);
		gl.glDisable(GL10.GL_TEXTURE_2D);

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}

